/*     */ package com.iris.egrant.utils.date;
/*     */ 
/*     */ import com.iris.egrant.utils.Assert;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.GregorianCalendar;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CalendarUtils
/*     */ {
/*     */   public static String now(DateFormator pattern) {
/*  28 */     Assert.notNull(pattern);
/*     */     
/*  30 */     GregorianCalendar gerCalendar = new GregorianCalendar();
/*  31 */     Date date = gerCalendar.getTime();
/*  32 */     SimpleDateFormat sdf = new SimpleDateFormat(pattern.toString());
/*  33 */     return sdf.format(date);
/*     */   }
/*     */ 
/*     */   
/*     */   public static String yestoday(String pattern) {
/*  38 */     Assert.notNull(pattern);
/*     */     
/*  40 */     GregorianCalendar gerCalendar = new GregorianCalendar();
/*  41 */     Date date = gerCalendar.getTime();
/*  42 */     SimpleDateFormat sdf = new SimpleDateFormat(pattern);
/*  43 */     return sdf.format(DateUtils.nextDays(date, -1));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String now() {
/*  52 */     return now(DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static <T> T now(Class<T> clazz) {
/*  64 */     Assert.notNull(clazz);
/*     */     
/*  66 */     if (GregorianCalendar.class.equals(clazz))
/*  67 */       return (T)new GregorianCalendar(); 
/*  68 */     if (Calendar.class.equals(clazz))
/*  69 */       return (T)new GregorianCalendar(); 
/*  70 */     if (Date.class.equals(clazz))
/*  71 */       return (T)(new GregorianCalendar()).getTime(); 
/*  72 */     if (String.class.equals(clazz)) {
/*  73 */       return (T)now(DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */     }
/*  75 */     throw new IllegalArgumentException("argument must be in [java.util.Calendar,java.util.GregorianCalendar,java.util.Date,String]");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar toCalendar(String time, DateFormator pattern) {
/*  82 */     Assert.notNull(time);
/*  83 */     Assert.notNull(pattern);
/*     */     
/*  85 */     SimpleDateFormat format = new SimpleDateFormat(pattern.toString());
/*  86 */     Date date = null;
/*     */     try {
/*  88 */       date = format.parse(time);
/*  89 */       GregorianCalendar calendar = new GregorianCalendar();
/*  90 */       calendar.setTime(date);
/*  91 */       return calendar;
/*  92 */     } catch (ParseException e) {
/*  93 */       throw new RuntimeException("[Pase Exception]: the time string doesn't match for pattern.");
/*     */     } 
/*     */   }
/*     */   
/*     */   public static GregorianCalendar toCalendar(String time) {
/*  98 */     Assert.notNull(time);
/*  99 */     return toCalendar(time, DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */   }
/*     */   
/*     */   public static long getDiffMillis(Calendar c1, Calendar c2) {
/* 103 */     Assert.notNull(c1);
/* 104 */     Assert.notNull(c2);
/*     */     
/* 106 */     long diff = c1.getTimeInMillis() - c2.getTimeInMillis();
/*     */     
/* 108 */     return diff;
/*     */   }
/*     */   
/*     */   public static long getDiffDays(Calendar c1, Calendar c2) {
/* 112 */     Assert.notNull(c1);
/* 113 */     Assert.notNull(c2);
/*     */     
/* 115 */     Calendar c1Copy = new GregorianCalendar(c1.get(1), c1.get(2), c1.get(5));
/* 116 */     Calendar c2Copy = new GregorianCalendar(c2.get(1), c2.get(2), c2.get(5));
/*     */     
/* 118 */     long diffMillis = getDiffMillis(c1Copy, c2Copy);
/*     */     
/* 120 */     long dayMills = 86400000L;
/* 121 */     long diffDays = diffMillis / dayMills;
/*     */     
/* 123 */     return diffDays;
/*     */   }
/*     */   
/*     */   public static int compare(Calendar c1, Calendar c2) {
/* 127 */     Assert.notNull(c1);
/* 128 */     Assert.notNull(c2);
/*     */     
/* 130 */     return c1.compareTo(c2);
/*     */   }
/*     */   
/*     */   public static String toString(Calendar c, DateFormator pattern) {
/* 134 */     Assert.notNull(c);
/* 135 */     Assert.notNull(pattern);
/*     */     
/* 137 */     Date date = c.getTime();
/* 138 */     SimpleDateFormat sdf = new SimpleDateFormat(pattern.toString());
/* 139 */     return sdf.format(date);
/*     */   }
/*     */   
/*     */   public static String toString(Calendar c) {
/* 143 */     Assert.notNull(c);
/* 144 */     return toString(c, DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */   }
/*     */   
/*     */   public static GregorianCalendar calculator(Calendar c, int diffDays) {
/* 148 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c.clone();
/* 149 */     cloneCalendar.add(5, diffDays);
/* 150 */     return cloneCalendar;
/*     */   }
/*     */   
/*     */   public static GregorianCalendar calculator(int diffDays) {
/* 154 */     return calculator(new GregorianCalendar(), diffDays);
/*     */   }
/*     */   
/*     */   public static Calendar beginTimeOfMonth(int year, int month) {
/* 158 */     Calendar first = new GregorianCalendar(year, month - 1, 1, 0, 0, 0);
/* 159 */     return first;
/*     */   }
/*     */   
/*     */   public static Calendar endTimeOfMonth(int year, int month) {
/* 163 */     Calendar first = new GregorianCalendar(year, month, 1, 0, 0, 0);
/* 164 */     first.add(14, -1);
/* 165 */     return first;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar preDaysCalendar(int preDays) {
/* 176 */     return preDaysCalendar(new GregorianCalendar(), preDays);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar preDaysCalendar(Calendar c1, int preDays) {
/* 188 */     GregorianCalendar cloneCalendar = (GregorianCalendar)c1.clone();
/* 189 */     cloneCalendar.add(5, -preDays);
/* 190 */     return cloneCalendar;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar parseToCalendar(String dateStringToParse) {
/* 201 */     return parseToCalendar(dateStringToParse, DateFormator.YEAR_MONTH_DAY_HH_MM_SS);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar parseToCalendar(String dateStringToParse, DateFormator pattern) {
/* 213 */     SimpleDateFormat format = new SimpleDateFormat(pattern.toString());
/* 214 */     Date date = null;
/*     */     try {
/* 216 */       date = format.parse(dateStringToParse);
/* 217 */       GregorianCalendar calendar = new GregorianCalendar();
/* 218 */       calendar.setTime(date);
/* 219 */       return calendar;
/* 220 */     } catch (ParseException e) {
/* 221 */       e.printStackTrace();
/* 222 */       throw new RuntimeException("[Pase Exception]: please check the input date string format.");
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar getStartDate(String date) {
/* 234 */     int week = getWeekByDate(date);
/* 235 */     GregorianCalendar beginGC = parseToCalendar(date + " 00:00:00");
/* 236 */     GregorianCalendar beginDate = preDaysCalendar(beginGC, week + 7 - 0);
/* 237 */     return beginDate;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static GregorianCalendar getEndDate(String date) {
/* 248 */     int week = getWeekByDate(date);
/* 249 */     GregorianCalendar endGC = parseToCalendar(date + " 23:59:59");
/* 250 */     GregorianCalendar endDate = preDaysCalendar(endGC, week + 6 - 6);
/* 251 */     return endDate;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int getWeekByDate(String date) {
/* 261 */     GregorianCalendar c = toCalendar(date, DateFormator.YEAR_MONTH_DAY);
/* 262 */     int weekDay = c.get(7);
/*     */     
/* 264 */     if (weekDay == 1) {
/* 265 */       weekDay = 7;
/*     */     } else {
/* 267 */       weekDay--;
/*     */     } 
/* 269 */     return weekDay;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static int getNowWeekDay() {
/* 278 */     GregorianCalendar c = new GregorianCalendar();
/* 279 */     int weekDay = c.get(7);
/*     */     
/* 281 */     if (weekDay == 1) {
/* 282 */       weekDay = 7;
/*     */     } else {
/* 284 */       weekDay--;
/*     */     } 
/* 286 */     return weekDay;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static boolean juageDate(int i) {
/* 293 */     if ((i % 4 == 0 && i % 100 != 0) || (i % 4 == 0 && i % 400 == 0)) {
/* 294 */       return true;
/*     */     }
/* 296 */     return false;
/*     */   }
/*     */   
/*     */   public static void main(String... args) {
/* 300 */     System.out.println(getNowWeekDay());
/*     */   }
/*     */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egran\\utils\date\CalendarUtils.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */